//
//  WNSlider.swift
//  WalkNovel
//
//  Created by Kevin on 2023/7/4.
//

import UIKit

class WNSlider: UISlider {
    
    var snHeight: CGFloat = 6
    
    var w: CGFloat = 20
    
    // 改变滑块的触摸范围
    override func thumbRect(forBounds bounds: CGRect, trackRect rect: CGRect, value: Float) -> CGRect {
        var trect = rect
        trect.origin.x -= w
        trect.size.width += w*2
        return super.thumbRect(forBounds: bounds, trackRect: trect, value: value)
    }
    
    override func minimumValueImageRect(forBounds bounds: CGRect) -> CGRect {
        return self.bounds
    }
    
    override func maximumValueImageRect(forBounds bounds: CGRect) -> CGRect {
        return self.bounds
    }
    
    override func trackRect(forBounds bounds: CGRect) -> CGRect {
        return CGRect.init(x: bounds.origin.x, y: bounds.origin.y, width: bounds.size.width, height: snHeight)
    }
    
    override func point(inside point: CGPoint, with event: UIEvent?) -> Bool {
        var bounds: CGRect = self.bounds
        bounds = CGRectInset(bounds, -10, -15)
        return CGRectContainsPoint(bounds, point)
    }
}
